package controler.userCommands;
import controler.A_State;
import controler.A_UserCommand;
import flash.geom.Point;

/**
 * @author Damien Mabin
 */

class ChangeUserViewPoint extends A_UserCommand
{
	private var m_DeltaX 		: Float;
	private var m_DeltaY 		: Float;
	private var m_DeltaZoom 	: Float;
	
	public function new(_NextState:A_State, _DeltaX:Float, _DeltaY:Float, _DeltaZoom:Float) 
	{
		super(_NextState);
		m_CanBeUndo = true;
		m_Stackable = true;
		
		m_DeltaX = _DeltaX;
		m_DeltaY = _DeltaY;
		m_DeltaZoom = _DeltaZoom;
	}
	
	override public function DoCommand():Void 
	{
		super.DoCommand();
		var currentVP : Point = A_UserCommand.s_Model.VUE_GetViewPoint();
		A_UserCommand.s_Model.CTRL_SetViewPoint(new Point(currentVP.x + m_DeltaX/A_State.s_Model.VUE_GetZoomLevel(), currentVP.y + m_DeltaY/A_State.s_Model.VUE_GetZoomLevel()));
		var currentZoom : Float = A_UserCommand.s_Model.VUE_GetZoomLevel();
		A_UserCommand.s_Model.CTRL_SetZoomLevel(currentZoom+m_DeltaZoom);
	}
	
	override public function UndoCommand():Void 
	{
		var currentVP : Point = A_UserCommand.s_Model.VUE_GetViewPoint();
		A_UserCommand.s_Model.CTRL_SetViewPoint(new Point(currentVP.x - m_DeltaX/A_State.s_Model.VUE_GetZoomLevel(), currentVP.y - m_DeltaY/A_State.s_Model.VUE_GetZoomLevel()));
		var currentZoom : Float = A_UserCommand.s_Model.VUE_GetZoomLevel();
		A_UserCommand.s_Model.CTRL_SetZoomLevel(currentZoom-m_DeltaZoom);
		super.UndoCommand();
	}
	
}